<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>添加配置</title>
	<link rel="stylesheet" href="__STATIC__/select2/select2.min.css">
	<link rel="stylesheet" href="__STATIC__/aui/aui.2.0.css">
	<style type="text/css">
		.pointer{cursor: pointer;}
	</style>
</head>
<body>
	<div class="aui-content">
			
			<div class="aui-row">
				<div class="aui-content aui-margin-b-15">
			        <ul class="aui-list aui-form-list">
			         <li class="aui-list-item">
			                <div class="aui-list-item-inner">
			                    <div class="aui-list-item-label">
			                        配送名称
			                    </div>
			                    <div class="aui-list-item-input">
			                        <input type="text" placeholder="配送名称" id="shipping_area_name" name='shipping_area_name' value="{$config.shipping_area_name|default=''}">
			                    </div>
			                </div>
			            </li>
			            <li class="aui-list-item">
			                <div class="aui-list-item-inner">
			                    <div class="aui-list-item-label">
			                        首重
			                    </div>
			                    <div class="aui-list-item-input">
			                        <select name='firstweight' class='select2' id="firstweight">
			                        		<php>
			                        			$k = 500 ;
			                        			for($i = 0 ; $i < 15 ; $i ++){
			                        				if($config['config']['first_weight'] == $k){
			                        					echo '<option value="'.$k.'" selected>'.$k.'克费用</option>';
			                        				}else{
			                        					echo '<option value="'.$k.'">'.$k.'克费用</option>';
			                        				}
			                        				$k = $k + 500 ; 
			                        			}
			                        		</php>
			                        </select>
			                    </div>
			                     <div class="aui-list-item-input">
			                         <input type="num"  placeholder="首重之内费用" id='money' value="{$config.config.money|number_format=###,0,2}">
			                    </div>
			                </div>
			            </li>
			            <li class="aui-list-item">
			                <div class="aui-list-item-inner">
			                    <div class="aui-list-item-label">
			                        续重
			                    </div>
			                    <div class="aui-list-item-input">
			                        <select name='secondweight' class='select2' id="secondweight">
			                       			 <php>
			                        			$k = 500 ;
			                        			for($i = 0 ; $i < 15 ; $i ++){
			                        				if($config['config']['second_weight'] == $k){
			                        					echo '<option value="'.$k.'" selected>每'.$k.'克费用</option>';
			                        				}else{
			                        					echo '<option value="'.$k.'">每'.$k.'克费用</option>';
			                        				}
			                        				$k = $k + 500 ; 
			                        			}
			                        		</php>
			                        </select>
			                    </div>
			                     <div class="aui-list-item-input">
			                         <input type="num"  placeholder="续重之内费用" id='add_money' value="{$config.config.add_money}">  
			                    </div>
			                </div>
			            </li>
			            <style type="text/css">
			            .aui-list-item-input{width:30% !important;float: right;}
			            </style>
			            <li class="aui-list-item">
			                <div class="aui-list-item-inner">
			               <div class="aui-list-item-label">
								    配送区域
								</div>
								<div class="aui-list-item-input">
								    <select name='area' class='select2' id="area1" onchange="get_area(this.value,'area2')" width="100px">
								        <option value="0">请选择省份</option>
								        <volist name='region' id='vo'>
								            <option value="{$vo.id}">{$vo.name}</option>
								        </volist>
								    </select>
			                    </div>
			                     <div class="aui-list-item-input">
								        <select name='area2' class='select2' id='area2' onchange="get_area(this.value,'area3')">
								            <option value="0">请选择城市</option>
								        </select>
								    </div>
								    <div class="aui-list-item-input">
								        <select name="area3" class='select2' id='area3'>
								            <option value="0">请选择地区</option>
								        </select>
								    </div>
			                </div>
			            </li>
			            <style type="text/css">#inputgroup{width:80% !important;}</style>
			             <li class="aui-list-item">
			             	 <div class="aui-list-item-input" id='inputgroup'></div>
			                <div class="aui-list-item-inner aui-list-item-center aui-list-item-btn">
			                    <div class="aui-btn aui-btn-info aui-margin-r-5" onclick = 'add()'>增加</div>
			                </div>
			            </li>
			            <li class="aui-list-item">
			                <div class="aui-list-item-inner aui-list-item-center aui-list-item-btn">
			                    <div class="aui-btn aui-btn-info aui-margin-r-5" id='submit'>提交</div>
			                    <div class="aui-btn aui-btn-danger aui-margin-l-5">取消</div>
			                </div>
			            </li>
			        </ul>
			    </div>
			</div>


	</div>
	<script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
	<script type="text/javascript" src="__STATIC__/layer/layer.js"></script>
	<script type="text/javascript" src="__STATIC__/select2/select2.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$('.select2').select2();
			$('#inputgroup').on('click' ,'.pointer' , function(){ 
				$(this).remove();
			})
			$('#submit').on('click' , function(){
				var data = {};
				data.id = '{$Think.get.id}';
				data.first_weight = parseFloat($('#firstweight').val()) ; 
				data.second_weight = parseFloat($('#seconeweight').val() );
				data.shipping_area_name = $('#shipping_area_name').val();
				data.shipping_area_code = '{$Think.get.code}';
				data.money = $('#money').val();
				data.add_money = $('#add_money').val();
				var areas  = $('.pointer') ; 
				if(areas.length < 1){alert("请选择区域");return;}
				var ids = ''; 
				$.each(areas , function(i,v){
					ids += $(v).attr('data-id') + ',';
				});
				data.ids = ids.substr(0 , ids.length -1 );
				$.post('__SELF__' , data , function(json){
					if(json.status){window.parent.location.reload();}
					else{alert(data.info);}
				});
			})
		})

		function get_area(val , emel){
			$.getJSON('{:U("Home/Public/get_child_region")}&pid='+val , function(data){
				if(emel == 'area2'){
					$('#area3').html('');
				}
				$('#' + emel).html('<option value="0">请选择</option>');
				html = '';
				$.each(data.data , function(i,v){
					html += '<option value='+v.id+'>'+v.name+'</option>';
				});
				$('#' + emel).append(html);
			});
		}

		function add(){
			var val ,con ; 
			var a3 = $('#area3').val();
			if(a3 != 0){ val = a3 ; con = $('#area3 option[value='+a3+']').text(); }
			var a2 = $('#area2').val();
			if(a2 != 0){ val = a2 ; con = $('#area2 option[value='+a2+']').text() }
			var a1 = $('#area1').val();
			if(a1 != 0){ val = a1 ; con = $('#area1 option[value='+a1+']').text() }
			if(typeof con == 'undefined'){return;}
			$('#inputgroup').append('<div class="aui-label aui-label-info pointer" id="data'+val+'"  data-id='+val+'>'+con+'</div>');
		}


	</script>
</body>
</html>
